Previous Book Contents Book Index Next

Inside Macintosh: Programming With JManager /
Chapter 1 - Using JManager / Handling Events


Update, Activate, and Resume Events

If the application receives an update event, it must update the currently active window. If the window corresponds to a frame, you must pass the update event to the frame using the JMFrameUpdate function (page 88). The AWT context can then update the actual window using a callback. Listing 1-12 shows an example of an update function.

Listing 1-12 Handling a frame update event

static void handleUpdate(WindowPtr win)
{
   JMFrameRef frame;
   BeginUpdate(win);
   SetPort(win);
   frame = (JMFrameRef) GetWRefCon(win);
   if (frame)
      JMFrameUpdate(frame, win->visRgn);
   else
      EraseRgn(win->visRgn);
   EndUpdate(win);
}
If an activate event occurs, then a window was made active (that is, brought to the front), and if that window is associated with a frame, you must activate the frame using the JMFrameActivate function (page 89). This action gives the frame the opportunity to highlight title bars, scroll bars, and so on. Activating a frame also installs the menu bar associated with the frame. Listing 1-13 gives an example of activating a frame.

Listing 1-13 Sending an activate event to a frame

static void handleActivate(Boolean active, WindowPtr window)
{
   JMFrameRef frame = (JMFrameRef) GetWRefCon(window);
   if (frame)
      JMFrameActivate(frame, active);
}
Note
The JMFrameActivate function can either activate or deactivate a frame depending on the Boolean value passed to it (the value of active in this example).
Similar to the activate event are the suspend and resume events, which can also occur when a window is activated or deactivated. When the user switches from one application to another, the newly selected application is sent a resume event, and the previously active one is sent a suspend event. This event affects all the applets embedded within an application, so you must call the JMFrameResume function (page 89) to suspend or resume all the existing frames.

Listing 1-14 shows how to send a resume event to all the frames associated with a client application.

Listing 1-14 Sending a resume event to frames

static void handleResume(Boolean resume)
{
   WindowPtr win = FrontWindow();
   while (win) {
      JMFrameRef frame = (JMFrameRef) GetWRefCon(win);
      if (frame)
         JMFrameResume(frame, resume);
      win = (WindowPtr) ((WindowPeek) win)->nextWindow;
   }
}
Note
The JMFrameResume function can either suspend or resume a frame depending on the Boolean value passed to it (the value of resume in this example).
This example cycles through all the visible windows used by the application and sends the event to those that are associated with frames. However, this example only works if every frame is associated with a window. If this is not the case, you must use some other method to send the resume event.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
23 APR 1997